exports.CreateLoginPop = function(_args) {
    if(_args === undefined) _args = {};
    if(_args.title === undefined) _args.title = 'Popover';

	Ti.App.Properties.setString('login_username_email', '');
	Ti.App.Properties.setString('login_password', '');
		
		
    var win = Ti.UI.createWindow({
    	top:0,
    	left:Titanium.Platform.displayCaps.platformWidth,
        width: Titanium.Platform.displayCaps.platformWidth,//320,
        height: Titanium.Platform.displayCaps.platformHeight,//480,
        opacity: 0,
        backgroundColor:'transparent'
    });
    var btwidth=200;
	var btheight=45;
    var backgroundImage,arrowimage;
    var topfirst,leftfirst,leftsecond,heightlabel,right,heighttext,space,bgcolor='#020202'	
	var aps='';
    if(Ti.Platform.osname== 'android') {
  		 backgroundImage= '../windows/images/popover/PopoverPortrait.png';
  		 arrowimage='../windows/images/popover/PopoverPortraitArrow.png';
  		 Titanium.include('../globals.js');
  		 Titanium.include('../cs/cs.js');
  		 Titanium.include('../windows/ModalActivityIndicatorWindow.js');
  		 aps='../';
  		 topfirst=30,leftfirst=40,leftsecond=200,heightlabel=21,right=40,heighttext=50,space=10
    }
    else {
   		  backgroundImage= 'windows/images/popover/PopoverPortrait.png';
   		  arrowimage='windows/images/popover/PopoverPortraitArrow.png';
   		  Titanium.include('globals.js');
   		  topfirst=30,leftfirst=40,leftsecond=200,heightlabel=21,right=40,heighttext=31,space=10
	
    }
    
    
    
    var fakeWin = Ti.UI.createView({
        width: Titanium.Platform.displayCaps.platformWidth,//300,
        height: Titanium.Platform.displayCaps.platformHeight,//350,
        top:0,// 65,
        backgroundColor:'transparent'
        //backgroundImage:Globals.backgroundImage_PanelHeaderBuyDetail,
    });
    win.add(fakeWin);

    win.addEventListener('close', function() {
        win = null;
    });

    win.addEventListener('click', function(e) {
        //alert(e.source);
        if(e.source === win) {
            win.close();
        }
    });

    var view = Ti.UI.createView({
        width:505,//,400
        height:290,//,418
        //top: 40,
        backgroundColor: 'transparent',
        backgroundImage:aps+'images/login.png',
        borderRadius: 8,
       // backgroundImage:Globals.backgroundImage_PanelHeaderBuyDetail,
    });
    fakeWin.add(view);

	/*
    fakeWin.add(Ti.UI.createLabel({
        text: _args.title,
        color:"#fff",
        textAlign:"center",
        height: 'auto',
        top: 10,
        font:{fontSize:18,fontWeight:"bold"}
    }));
	*/
	
    _args.view.open = function() {
        win.open();
        
       
        
        
        var a1 = Titanium.UI.createAnimation();
      
        a1.curve=Titanium.UI.ANIMATION_CURVE_LINEAR;
        a1.left=0;
        a1.opacity = 1;
        a1.duration = 300;
        win.animate(a1);
    };

    _args.view.close = function() {
       
      win.hide();
    };

	
	var txtEmail = Titanium.UI.createTextField({
	    //borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
	    left:58,//72,
	    top: 71,//149,
	    height: 45,//42,
	    width:375,//253,
	    hintText: 'Nhập địa chỉ hộp thư của bạn',
	    color:'Black',
	    backgroundColor:'transparent',
	    //borderColor:'Black',
	    //borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
	    font: {fontFamily: 'Helvetica', fontSize: Ti.App.Properties.getString('fontsizeDialog')},
	    //opacity:0.1
	});

	view.add(txtEmail);
	
	var txtPass = Titanium.UI.createTextField({
	    //borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
	    left:58,// 72,//58,
	    top: 130,//234,//130,
	    height:45,//42,// 45,
	    width:375,//253,//375,
	    hintText: 'Nhập mật khẩu bảo mật',
	    passwordMask:true,
	  	color:'Black',
	    backgroundColor:'transparent',
	    //borderColor:'Black',
	    font: {fontFamily: 'Helvetica', fontSize: Ti.App.Properties.getString('fontsizeDialog')},
	    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,  
	    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,  
	    //opacity:0.1
	
	});
	view.add(txtPass);
	/*
	var btCreateAccount = Titanium.UI.createButton({
		//title:'Đăng nhập',
		font:{
			fontSize:Ti.App.Properties.getString('fontsizeDefault')//,
			//fontWeight:'bold'
		},
		width:121,//93,//121	,
		height:34,//33,//34	,
		left: 198,//57,//198	,
	    top: 52,//363,//52,
		backgroundColor:'transparent',
		color:'transparent',
		backgroundDisabledColor:'transparent',
		backgroundSelectedColor:'transparent',
		backgroundDisabledColor:'transparent',
		borderColor:'transparent',
		borderWidth:0,
		backgroundColor:'transparent',
		opacity:0.1
		
	});
	
	btCreateAccount.addEventListener('click',function()
	{
		
		var table = Ti.UI.createTableView();
	
		var RegisterPop = require('windows/RegisterPop').CreateRegisterPop
		var pop = new RegisterPop({
	        title: Globals.login_register,
	        view: table,
	        isRegister:1,
	        top:0
	    });
	    pop.open();
	});
	view.add(btCreateAccount);
	*/
	
	
	
	var btLoginDialog = Titanium.UI.createButton({
		//title:'Đăng nhập',
		font:{
			fontSize:Ti.App.Properties.getString('fontsizeDefault')//,
			//fontWeight:'bold'
		},
		width:121,//93,//121	,
		height:34,//33,//34	,
		right: 198,//70,//198	,
	    bottom: 52,//363,//52,
	
		color:'transparent',
		backgroundDisabledColor:'transparent',
		backgroundSelectedColor:'transparent',
		backgroundDisabledColor:'transparent',
		borderColor:'transparent',
		borderWidth:0,
		backgroundColor:'transparent',
		opacity:0.1
		
	});
	btLoginDialog.addEventListener('click',function()
	{
		 if(Ti.Platform.osname== 'android') {
		  	Ti.UI.Android.hideSoftKeyboard();
		 }
		
		 if (Ti.Network.online) {
		
		 	var Email=txtEmail.getValue();
		 	var Password=txtPass.getValue();
		 
		    if(Email=='')
		 	{
		 		require('settings').createAlertDialog(Globals.title,txtEmail.getHintText());
		 		txtEmail.focus();
		 		return
		 	}
		 	else if (!require('settings').checkemail(txtEmail.value))
			{
				require('settings').createAlertDialog(Globals.title,Globals.checkemailvalid);
		 		txtEmail.focus();
		 		return
			}
		 	else if(Password=='')
		 	{
		 		require('settings').createAlertDialog(Globals.title,txtPass.getHintText());
		 		txtPass.focus();
		 		return
		 	}
	 		else
	 		{
	 			Codestrong.ui.activityIndicator.showModal(Globals.loading_checkAccount, Globals.timeout, Globals.loadingTimeout);
	 			getLoginUser(Email,Password)
	 		}
		 	
		 }
		 else
		 {
		  	   require('settings').createAlertConnectError();
		 }
	})
	view.add(btLoginDialog);
	
	
	
	
	
	
	var btCancelDialog = Titanium.UI.createButton({
		title:'Huỷ bỏ',
		font:{
								fontSize:Ti.App.Properties.getString('fontsizeDefault')//,
								//fontWeight:'bold'
			},
		//backgroundImage:Globals.backgroundImage_button,
		//backgroundSelectedImage:Globals.backgroundSelectedImage,
		//backgroundDisabledImage: Globals.backgroundDisabledImage,
		width:121,//28,//121	,
		height:34,//25,//34	,
		right: 70,//9,//70	,
	    bottom: 52,//0,//52,
		//color:Globals.foreColor,
		backgroundColor:'transparent',
		color:'transparent',
		backgroundDisabledColor:'transparent',
		backgroundSelectedColor:'transparent',
		backgroundDisabledColor:'transparent',
		borderColor:'transparent',
		borderWidth:0,
		backgroundColor:'transparent',
		opacity:0.1
		
	});
	btCancelDialog.addEventListener('click',function()
	{
		/*
		if(Ti.Platform.osname== 'android') {
		  	Ti.UI.Android.hideSoftKeyboard();
		}
	
		var a1 = Titanium.UI.createAnimation();
        a1.right=800;
        a1.curve=Titanium.UI.ANIMATION_CURVE_LINEAR;
       
        a1.opacity = 0;
        a1.duration = 5000;
       	win.animate(a1);
        win.close(a1)
        */
		win.close({animated:true})
	})
	view.add(btCancelDialog);





	var getLoginUser = function(Email,Password) {
	//activityIndicator.show();
	var row = null;
	var data = [];
	var param = {   
	  "UserName_Email" : Email,
	  "Password" : Password
	};
	try {  	
	   	   var xhr = Titanium.Network.createHTTPClient({
		   onload : function(e) 
		   {
		         Titanium.API.info(this.responseText);
				 json = this.responseText;
				 json=json.replace('<string xmlns="http://tempuri.org/">', '');
				 json=json.replace('<?xml version="1.0" encoding="utf-8"?>', '');
				 json=json.replace('</string>', '');
				 //alert(FullName+','+Sex+','+Birthday+','+Address+','+Email+','+UserName+','+Password+','+Postdate)
				 //alert(json)
			
				 response = JSON.parse(json);
			     //alert(response.OBJECT.length);
			     if(response.OBJECT.length>=1)
			     {
			     	//require('settings').createAlertDialog(Globals.title,Globals.loginsuccesfull);
			     	Ti.App.Properties.setInt('isLogin', 1);
			     	Ti.App.Properties.setInt('login_username_id', response.OBJECT[0].Id);
			     	Ti.App.Properties.setString('login_username_email', response.OBJECT[0].Email);
			     	Ti.App.Properties.setString('login_username', response.OBJECT[0].UserName);
			     	Ti.App.Properties.setString('login_email', response.OBJECT[0].Email);
					Ti.App.Properties.setString('login_password', response.OBJECT[0].PasswordNoEncode);
				
					Ti.App.Properties.setString('login_FullName', response.OBJECT[0].FullName);
					Ti.App.Properties.setString('login_Address', response.OBJECT[0].Address);
					Ti.App.Properties.setString('login_Sex', response.OBJECT[0].Sex);
					Ti.App.Properties.setString('login_Birthday', response.OBJECT[0].Birthday);
					Ti.App.Properties.setString('login_Card', response.OBJECT[0].cr_value_card);
					
					Ti.App.Properties.setString('IsBuyProgram', response.OBJECT[0].IsBuyProgram);
					Ti.App.Properties.setString('IsActiveDownload', response.OBJECT[0].IsActiveDownload);
					
					if(_args.isCheck==-1)
					{
						////MUA BAI GIANG POPUP
						Ti.App.fireEvent('LectureDetail:btMuaBaiGiangPopup',{LectureId:_args.LectureId})
					}
					if(_args.isCheck==0)
					{
						////MUA BAI GIANG
						Ti.App.fireEvent('LectureDetail:btMuaBaiGiang',{LectureId:_args.LectureId})
					}
					else if(_args.isCheck==1)
					{
						////Mua Chuong trinh
						Ti.App.fireEvent('LectureDetail:btMuaChuongTrinh')
					}
					else if(_args.isCheck==2)
					{
						////Kich hoat tai
						Ti.App.fireEvent('LectureDetail:btDowloadLecture')
					}
					else if(_args.isCheck==3)
					{
						////Like bai giang
						Ti.App.fireEvent('LectureDetail:btLike')
					}
					
					
					win.close();
			     }
			     else
			     {
			     	Ti.App.Properties.setInt('isLogin',0);
			     	require('settings').createAlertDialog(Globals.title,Globals.loginunsuccesfull);
			     }
			    
				
				Codestrong.ui.activityIndicator.hideModal();
		   }, 
		   onerror : function(e) {
		   	 Ti.App.Properties.setInt('isLogin',0);
		   	 Codestrong.ui.activityIndicator.hideModal();
		   },
		   timeout : Globals.timeout //5000
    
		});
		xhr.open("POST",Globals.serviceurl_UserLogin);
		xhr.send(param);
		//return data;
	   		    
	 	} catch (e) {
	 			Ti.App.Properties.setInt('isLogin',0);
	            Ti.API.info(e);
	        }
	
	};
	
	
    return _args.view;
};